local sk__yeyan = fk.CreateSkill {

  name = "sk__yeyan",

  tags = { Skill.Limited, },

}



sk__yeyan:addEffect("active", {
  name = "sk__yeyan",
  anim_type = "offensive",
  min_card_num = 1,
  max_card_num = 4,
  target_num = 0,
  prompt = "#sk__yeyan",
  can_use = function(self, player)
    return player:usedSkillTimes(sk__yeyan.name, Player.HistoryGame) == 0
  end,
  card_filter=function (self, player, to_select, selected)
    return #selected < 4 and not player:prohibitDiscard(to_select) and Fk:currentRoom():getCardArea(to_select) == Card.PlayerHand
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local red, black = 1, 1
    for _, id in ipairs(effect.cards) do
      if Fk:getCardById(id).color == Card.Red then
        red = red + 1
      elseif Fk:getCardById(id).color == Card.Black then
        black = black + 1
      end
    end
    room:throwCard(effect.cards, sk__yeyan.name, player, player)
    if player.dead then return end
    local tos_choose = room:askForChoosePlayers(player, table.map(room.alive_players, Util.IdMapper), 1, black,
      "#sk__yeyan-choose:::"..black..":"..red, sk__yeyan.name, true)
    local tos=table.map(tos_choose, function(id) return room:getPlayerById(id) end)
    if #tos > 0 then
      room:sortByAction(tos)
      if red * #tos > 4 then
        room:loseHp(player, 3, sk__yeyan.name)
      end
      for _, id in ipairs(tos) do
        local p = id
        if not p.dead then
          room:damage{
            from = player,
            to = p,
            damage = red,
            damageType = fk.FireDamage,
            skillName = sk__yeyan.name,
          }
        end
      end
    end
  end
})

return sk__yeyan